package org.shreker.shan.core.service.impl;

import java.util.ArrayList;
import java.util.List;
import org.shreker.shan.base.queryobject.QueryObject;
import org.shreker.shan.core.domain.Log;
import org.shreker.shan.core.mapper.LogMapper;
import org.shreker.shan.core.service.ILogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LogServiceImpl implements ILogService {
	
	@Autowired
	private LogMapper logMapper;

	@Override
	public void save(Log log) throws Exception {
		logMapper.insert(log);
	}

	@Override
	public Log get(Long id) throws Exception {
		return logMapper.selectByPrimaryKey(id);
	}

	@Override
	public Long queryCount(QueryObject queryObject) {
		return logMapper.queryCount(queryObject);
	}

	@Override
	public List<Log> query(QueryObject queryObject) {
		Long count = queryCount(queryObject);
		queryObject.calcPageInfo(count.intValue());
		if (count > 0) {
			return logMapper.query(queryObject);
		}
		return new ArrayList<>();
	}
	
	@Override
	public Long queryCountByUserId(QueryObject queryObject, Long userId) {
		return logMapper.queryCountByUserId(queryObject, userId);
	}

	@Override
	public List<Log> queryByUserId(QueryObject queryObject, Long userId) {
		Long count = queryCountByUserId(queryObject, userId);
		queryObject.calcPageInfo(count.intValue());
		if (count > 0) {
			return logMapper.queryByUserId(queryObject, userId);
		}
		return new ArrayList<>();
	}
	
}
